<template>
  <div class="evaluation-table">
    <table class="table" :class="tableClass">
      <thead :class="theadClasses">
        <tr>
          <slot name="columns">
            <th v-for="column in columns" :key="column">{{ column }}</th>
          </slot>
        </tr>
      </thead>

      <tbody :class="tbodyClasses">
        <tr v-for="(item, index) in data" :key="index">
          <slot :row="item">
            <td v-for="(column, colIndex) in columns" :key="colIndex">
              {{ itemValue(item, column) }}
            </td>
          </slot>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  name: "EvaluationTable",
  props: {
    tableClass: {
      type: String,
      default: "table-striped",
    },
    theadClasses: {
      type: String,
      default: "custom-thead",
    },
    tbodyClasses: {
      type: String,
      default: "",
    },
    data: {
      type: Array,
      default: () => [],
    },
    columns: {
      type: Array,
      default: () => ["指标", "分数", "评估等级", "备注"],
    },
  },
  methods: {
    itemValue(item, column) {
      return item[column.toLowerCase()] || "-";
    },
  },
};
</script>

<style scoped>
.evaluation-table {
  margin: 20px 0;
  overflow-x: auto;
  border-radius: 8px;
  box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
  background: #ffffff;
  padding: 10px;
}

.evaluation-table table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 8px;
  overflow: hidden;
}

/* 头部样式 - 浅蓝色渐变 */
.evaluation-table .custom-thead {
  background: linear-gradient(135deg, #5b9bd5, #87c1e9);
  color: white;
  text-transform: uppercase;
  font-weight: bold;
  letter-spacing: 1px;
  text-align: center;
}
.evaluation-table th,
.evaluation-table td {
  text-align: left; /* 让表头和内容左对齐 */
  padding: 12px;
}



/* 头部单元格 */
.evaluation-table th {
  padding: 12px;
  text-align: left;
  font-weight: bold;
  letter-spacing: 0.5px;
}

/* 单元格样式 */
.evaluation-table td {
  padding: 12px;
  border-bottom: 1px solid #ddd;
  color: #333;
  font-size: 14px;
}

/* 偶数行背景色 */
.evaluation-table tbody tr:nth-child(even) {
  background: #f9f9f9;
}

/* 悬停行效果 */
.evaluation-table tbody tr:hover {
  background: rgba(74, 144, 226, 0.15);
  transition: background 0.3s ease-in-out;
}

/* 让表格内容更紧凑 */
.evaluation-table th,
.evaluation-table td {
  white-space: nowrap;
}

/* 响应式优化 */
@media (max-width: 768px) {
  .evaluation-table table {
    font-size: 12px;
  }
  .evaluation-table th,
  .evaluation-table td {
    padding: 8px;
  }
}
</style>
